package com.hzjh.base.web.process

import android.content.Context
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.ProcessUtils
import com.blankj.utilcode.util.Utils
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.hzjh.base.web.IBridgeInvokeWebProcess
import kotlin.system.exitProcess
import com.hzjh.base.web.util.WebLog

//通用交互中转站
class CommonBridge : IBridgeCommand {
    private val TAG="IBridgeCommand"
    companion object{
        var preLoadUrlBridgeI:PreLoadUrlBridgeI?=null //预加载
    }
    override fun exec(params: JsonObject?, callback: IBridgeInvokeWebProcess?) {
        WebLog.d(TAG,"${ProcessUtils.getCurrentProcessName()} --- $params")
        params?.let {
            val commonKey=it.get("commonKey").asString
            val params=Gson().toJson(it.get("params")?:"")
            val gson= Gson()
            when(commonKey){
                BridgeCommand.Common.switchSite->{
                    //同步切换站点
                    val sitStringUpCase=gson.fromJson(params, String::class.java)

                }
                BridgeCommand.Common.previousEvent->{
                    //同步埋点前置位
                    val previousEvent=gson.fromJson(params, String::class.java)

                }
                BridgeCommand.Common.resetClient->{
                    //同步请求头

                }
                BridgeCommand.Common.preLoadUrl->{
                    //预加载web
                    val cacheUrl=gson.fromJson(params, String::class.java)
                    preLoadUrlBridgeI?.preLoadUrl(Utils.getApp(),cacheUrl)
                }
                BridgeCommand.Common.exitApp->{
                    //退出app
                    exitProcess(0)
                }
                BridgeCommand.Common.clearUserAgentData->{
                    //清空web的UserAgent

                }
                BridgeCommand.Common.toHomeWish->{
                    //跳首页心愿单页面

                }
                else -> {}
            }
        }
    }
}